<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: Content-Type');
header('Content-type: application/json');

$paged = null;

if ( isset( $_GET[ 'page' ] ) && isset( $_GET[ 'page' ] ) ) {
	$paged = $_GET[ 'page' ];
}

$RESTful_res = json_encode( array(
	"error" => "Page Not Found", 
	"code" => 1001
) );


if ( $paged == 1 ) {
	$RESTful_res = '{
		"page":1,
		"per_page":5,
		"total":13,
		"total_pages":3,
		"data":[
		  {
			"id":1,
			"email":"george.bluth@reqres.in",
			"name":"George",
			"avatar":""
		  },
		  {
			"id":2,
			"email":"janet.weaver@reqres.in",
			"name":"Janet",
			"avatar":""
		  },
		  {
			"id":3,
			"email":"emma.wong@reqres.in",
			"name":"Emma",
			"avatar":""
		  },
		  {
			"id":4,
			"email":"eve.holt@reqres.in",
			"name":"Eve",
			"avatar":""
		  },
		  {
			"id":5,
			"email":"charles.morris@reqres.in",
			"name":"Charles",
			"avatar":""
		  }
		]
	  }';

}



if ( $paged == 2 ) {
	$RESTful_res = '{
		"page":2,
		"per_page":5,
		"total":13,
		"total_pages":3,
		"data":[
		  {
			"id":6,
			"email":"george.bluth@reqres.in",
			"name":"George(page 2)",
			"avatar":""
		  },
		  {
			"id":7,
			"email":"janet.weaver@reqres.in",
			"name":"Janet(page 2)",
			"avatar":""
		  },
		  {
			"id":8,
			"email":"emma.wong@reqres.in",
			"name":"Emma(page 2)",
			"avatar":""
		  },
		  {
			"id":9,
			"email":"eve.holt@reqres.in",
			"name":"Eve(page 2)",
			"avatar":""
		  },
		  {
			"id":10,
			"email":"charles.morris@reqres.in",
			"name":"Charles(page 2)",
			"avatar":""
		  }
		]
	  }';

}



if ( $paged == 3 ) {
	$RESTful_res = '{
		"page":3,
		"per_page":5,
		"total":13,
		"total_pages":3,
		"data":[
		  {
			"id":11,
			"email":"george.bluth@reqres.in",
			"name":"George(page 3)",
			"avatar":""
		  },
		  {
			"id":12,
			"email":"janet.weaver@reqres.in",
			"name":"Janet(page 3)",
			"avatar":""
		  },
		  {
			"id":13,
			"email":"emma.wong@reqres.in",
			"name":"Emma(page 3)",
			"avatar":""
		  }
		]
	  }';

}



echo $RESTful_res;

